$(document).ready(function () {
    initNexttrip();
    initCreatedtopics();
});

function initNexttrip() {
    var table = $('#table_nexttrip').DataTable({
        ajax: {
            url: "/Trabalho_PD/webresources/WebServiceBoleias/getAllRecentTrips/" + 10,
            type: "GET",
            dataSrc: "trip"
        },
        order: [[ 0, "asc" ]],
        columns: [
            {data: 'departueDate'},
            {data: 'arrivalDate'},
            {data: 'departue_address'},
            {data: 'destination_address'},
            {data: 'car_brand'},
            {
                "className": 'details-control',
                "orderable": false,
                "data": null,
                "defaultContent": '<i class="btn btn-info fa fa-search fa-2x"></i>'
            }
        ]

    });

    $('#table_nexttrip tbody').on('click', 'td.details-control', function () {
        var tr = $(this).closest('tr');
        var data = table.row(tr).data();
        location.href = '/Trabalho_PD/tripinformation.html?id=' + data["id_trip"];
    });
}

function initCreatedtopics() {
    var table = $('#table_createdtopics').DataTable({
        ajax: {
            url: "/Trabalho_PD/webresources/WebServiceBoleias/getAllRecentTopics/" + 10,
            type: "GET",
            dataSrc: "topic"
        },
        order: [[ 0, "desc" ]],
        columns: [
            {data: 'created_date'},
            {data: 'title'},
            {data: 'name_user'},
            {
                "className": 'details-control',
                "orderable": false,
                "data": null,
                "defaultContent": '<i class="btn btn-info fa fa-search fa-2x"></i>'
            }
        ]

    });

    $('#table_createdtopics tbody').on('click', 'td.details-control', function () {
        var tr = $(this).closest('tr');
        var data = table.row(tr).data();
        location.href = '/Trabalho_PD/seetopic.html?id=' + data["id_topic"];
    });
}


